package com.java3_21;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Ticket {
    private int ticket;

    public Ticket() {
    }

    public int getTicket() {
        return ticket;
    }

    public void setTicket(int ticket) {
        this.ticket = ticket;
    }

    //默认是非公平锁
    //不使用公平锁就很容易造成线程饥饿
    Lock lock = new ReentrantLock(true);
    public void PrintAA(){
        lock.lock();
        try{
            System.out.println("AAAAAAAAA");
        }finally {
            lock.unlock();
        }
    }

    public void PrintBB(){
        lock.lock();
        try {
            System.out.println("BBBBBBBBBBBBB");
        } finally {
            lock.unlock();
        }
    }
}
